import preutils from './preutils.js'
import http from './http.js'
import api from './api.js'
export default {
	 getOauthData() {
	 	// let e = this.aes_utils.AesEncrypt('5')
	 	// console.log(e)
	 	// let d = this.aes_utils.AesDecrypt(e)
	 	// console.log(d)
	 	//加密值
	 	// let e = this.AES.AES.encrypt('5','123456','')
	 	// let e = this.AES.AES.encrypt('5',key,iv)
	 	// console.log(e)
	 	//解密值
	 	// let d =this.AES.AES.decrypt(e,key,iv)
	 	// let d =this.AES.AES.decrypt(e,'123456','')
	 	// console.log(d)
	 	http.sendRequest({
	 		api:api.common.getOauthApi,
	 		data: {
	 			response_type: preutils.responseType,
	 			scope: preutils.scopeBasic,
	 			client_id: preutils.clientId,
	 			redirect_uri: preutils.redirectUri ,
	 			state: preutils.state
	 		},
	 		success: res => {
	 			 this.getOtokenData(res.data.code);
	 		},
	 		fail:err =>{
	 			
	 		}
	 	});
	 },
	 
	 getOtokenData(code) {
	 	http.sendRequest({
	 		api:api.common.getOtokenApi,
	 		data: {
	 			code: code,
	 			grant_type: preutils.grantType,
	 			client_id: preutils.clientId,
	 			redirect_uri: preutils.redirectUri,
	 			client_secret: preutils.clientSecret,
	 			scope: preutils.scopeBasic
	 		},
	 		success: res => {
	 			uni.setStorageSync(preutils.accessToken,res.access_token);
	 			// console.log(accessToken);
	 		},
	 		fail:err =>{
	 			
	 		}
	 	});
	 },

	 // 获取code 和openid
	 getSysInfo(){
		// uni.login({
		// 	success:function(res){
		// 		 http.sendRequest({
		// 		 	api: api.common.getMiniAppOpenidApi,
		// 		 	data: {login_code:res.code},
		// 		 	success: res => { 
		// 				console.log(res)
		// 				uni.setStorageSync('openid', res.data.openid)
		// 		 	},
		// 		 	fail: err => {
				 
		// 		 	}
		// 		 }); 
		// 	}
		// })
	 },
	  
}
